﻿using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using System.IO;
using System.Windows.Media.Imaging;
using VIA.Integration;
using VIA.Integration.Hikvision.Presentation;
using VIA.Integration.LeadShine.Presentation;
using VIA.Modularity;
using VIA.Presentation.Services;
using VIA.RbacPassport;
using VIA.RbacPassport.Presentation;
using VIA.SiMoJi.Domain;
using VIA.VTPlatformService;

namespace VIA.SiMoJi.Presentation
{
    [DependsOn(typeof(VIA.Integration.Presentation.IntegrationPresentationModule))]
    [DependsOn(typeof(VIA.RbacPassport.Presentation.RbacPassportPresentationModule))]
    [DependsOn(typeof(VIA.OperatingRecord.Presentation.VIAOperatingRecordPresentationModule))]
    [DependsOn(typeof(SiMoJiDomainModule))]
    [DependsOn(typeof(VIAVTPlatformServiceModule))]
    [DependsOn(typeof(HikvisionPresentationModule))]
    [DependsOn(typeof(VIAIntegrationLeadShinePresentationModule))]
    public class SiMoJiPresentationModule : AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            context.Services.AddTransient<IPermissionProvider, PermissionProvider>();
            string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logo.png");
            Configure<LoginOption>(opt =>
            {
                opt.Image = new BitmapImage(new Uri(path));
            });
        }

        public override void OnPostApplicationInitialization(ApplicationInitializationContext context)
        {
            var option = context.ServiceProvider.GetService<IOptions<RbacPassortOption>>();
            var v = option.Value;
            v.AutoLogout(config => config = null);
            //v.AutoLogout(x =>
            //{
            //    x.Mode = AutoLogoutMode.WhenNoOperation;
            //    x.Interval = TimeSpan.FromMinutes(3);
            //});
        }

        public override void PostConfigureServices(ServiceConfigurationContext context)
        {
            Configure<RbacPassortOption>(x =>
            {
                x.LimitLoginMode = UserLoginMode.AccountAndPassword;
            });
        }
    }
}
